// 封装uni请求 https://ceshi2.dishait.cn/api/v1/hottopic

// import { webUrl } from './config.js'
let webUrl = 'https://ceshi2.dishait.cn/api/v1'
import store from '@/store/index'
function request(options) {
	let header = { "content-type": "application/json" }
	if (options.token) {
		header = { "token": store.state.token }
	}
	return new Promise((resolve, reject) => {
		uni.request({
			url: webUrl + options.url,
			method: options.method,
			data: options.data,
			header,
			success: (res) => {
				if (options.default) {
					resolve(res)
				}
				if (res.statusCode === 200) {
					if (res.data.data) {
						resolve(res.data.data)
					} else {
						resolve(res.data)

					}
				} else {
					resolve(res)
				}
			},
			fail: (err) => {
				uni.showToast({
					title: '服务器异常',
					duration: 2000,
					icon: 'none'
				});
				return reject(err)
			}
		})
	})

}
export default request